package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;




import com.wicket.okrapp.base.service.MOmsVirtualOrgMemberDeptService;
import com.wicket.okrapp.base.service.dto.common.ContentVirtualOrgMemberDeptDto;
import com.wicket.okrapp.base.service.dto.common.VirtualOrgMemberDeptDto;
import com.wicket.okrapp.base.service.dto.req.*;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsVirtualOrgMemberDeptMapper;
import com.wicket.okrapp.dal.po.mbg.OmsVirtualOrgMemberDept;
import com.wicket.okrframework.common.annotations.BanAuto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsVirtualOrgMemberDeptServiceImpl
        extends ServiceImpl<OmsVirtualOrgMemberDeptMapper, OmsVirtualOrgMemberDept>
        implements MOmsVirtualOrgMemberDeptService {

    @Autowired
    OmsVirtualOrgMemberDeptMapper omsVirtualOrgMemberDeptMapper;

    /**
   * 3-6-03批量查资料匹配虚拟成员部门[2540]
   * gen by moon at 10/16/2022, 7:14:10 AM
   */
 @Trace(operationName = "3-6-03批量查资料匹配虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  batchQueryInfoDataVirtualOrgMemberDept(BatchQueryInfoDataVirtualOrgMemberDeptReq reqDto) {
     
        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getVirtualOrgMemberDeptList()==null || reqDto.getVirtualOrgMemberDeptList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("dept_id", reqDto.getVirtualOrgMemberDeptList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }

    /**
   * 3-6-03查虚拟成员部门详情[2518]
   * gen by moon at 9/7/2022, 3:56:56 PM
   */
 @Trace(operationName = "3-6-03查虚拟成员部门详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
 @BanAuto
  @Transactional(rollbackFor=Exception.class)
  public  OmsVirtualOrgMemberDept  queryVirtualOrgMemberDeptDetail(QueryVirtualOrgMemberDeptDetailReq reqDto) {
     
        try {
         //reqDto.setStartTime();//TIME_SLICE_START_TIME  TODO ruizhe dong
//reqDto.setEndTime();//TIME_SLICE_END_TIME  TODO ruizhe dong
reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            if(reqDto.getStartTime()!=null && reqDto.getEndTime()!=null){
                queryWrapper.le("start_time",reqDto.getStartTime());
                queryWrapper.ge("end_time",reqDto.getEndTime());
                reqDto.setStartTime(null);
                reqDto.setEndTime(null);
            }
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsVirtualOrgMemberDept> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsVirtualOrgMemberDept retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }

    /**
   * 3-6-03新增虚拟成员部门[2355]
   * gen by moon at 10/16/2022, 7:14:09 AM
   */
 @Trace(operationName = "3-6-03新增虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addVirtualOrgMemberDept(OmsVirtualOrgMemberDept omsVirtualOrgMemberDept) {
     omsVirtualOrgMemberDept.setVirtualOrgMemberDeptId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsVirtualOrgMemberDept.setEndTime(CommonFunctionHelper.getFutureTime());//FUTURE_CURRENT_TIME
omsVirtualOrgMemberDept.setBatchEndtTime(CommonFunctionHelper.getFutureTime());//FUTURE_CURRENT_TIME
omsVirtualOrgMemberDept.setIsUpdate("TRUE");
omsVirtualOrgMemberDept.setUpdateStatus("NEW");
omsVirtualOrgMemberDept.setIsEditing("TRUE");
omsVirtualOrgMemberDept.setArchivngType("NOT_ARCHIVE");
omsVirtualOrgMemberDept.setIsArchive("FALSE");
omsVirtualOrgMemberDept.setSubjectLifeCycle("EDITING");
omsVirtualOrgMemberDept.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsVirtualOrgMemberDept.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsVirtualOrgMemberDept.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsVirtualOrgMemberDept.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsVirtualOrgMemberDept.setIsValid("FALSE");
omsVirtualOrgMemberDept.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsVirtualOrgMemberDept.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsVirtualOrgMemberDept)){
        return omsVirtualOrgMemberDept.getVirtualOrgMemberDeptId();
     }else {
        return "-1";
     }
    
  }

    /**
   * 3-6-03批量查内容匹配虚拟成员部门[2257]
   * gen by moon at 8/29/2022, 12:41:29 PM
   */
 @Trace(operationName = "3-6-03批量查内容匹配虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
 @BanAuto
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  batchQueryContentVirtualOrgMemberDept(BatchQueryContentVirtualOrgMemberDeptReq reqDto) {
     try {
         QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
         if(reqDto.getContentVirtualOrgMemberDeptList()==null || reqDto.getContentVirtualOrgMemberDeptList().isEmpty()){
             return new ArrayList<>();
         }
         //将内容标识提取出来，要注意 这个地方的in 不是使用主键，要使用同名字段.
         List<String> ids = reqDto.getContentVirtualOrgMemberDeptList().stream().map(ContentVirtualOrgMemberDeptDto::getEntityId).collect(Collectors.toList());
         queryWrapper.in("entity_id", ids);

         //正常构建查询条件
         Map<String, Object> fieldInfoMap = null;
         fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
         List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
         CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
         List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
         CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
         likeList.addAll(compareList);
         CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
//         queryWrapper.orderByDesc("order_number");
         queryWrapper.orderByDesc("operate_time");

         //执行查询
         List<OmsVirtualOrgMemberDept> retListDataTmp = super.list(queryWrapper);

         if(reqDto.getContentVirtualOrgMemberDeptList()!=null && reqDto.getContentVirtualOrgMemberDeptList().size()>0){
             if(reqDto.getContentVirtualOrgMemberDeptList().get(0).getEndTime()==null){
                 return retListDataTmp;
             }
         }

         //先构建索引
         Map<String,ContentVirtualOrgMemberDeptDto> indexInfo = new HashMap<>();
         for(ContentVirtualOrgMemberDeptDto oneMember : reqDto.getContentVirtualOrgMemberDeptList()){
             indexInfo.put(oneMember.getEntityId(),oneMember);
         }
         //按时间过滤
         Map<String,List<OmsVirtualOrgMemberDept>> retMapByDate = new HashMap<>();
         for(OmsVirtualOrgMemberDept oneData: retListDataTmp){
             ContentVirtualOrgMemberDeptDto standData = indexInfo.get(oneData.getEntityId());

             if(standData==null){
                 continue;
             }
             if(standData.getEndTime()==null || standData.getStartTime()==null || oneData.getStartTime()==null || oneData.getEndTime()==null){
                 continue;
             }
             //此处时间字段，一定是同名字段
             if(standData.getEndTime().compareTo(oneData.getStartTime())>=0 && standData.getEndTime().compareTo(oneData.getEndTime())<=0){
                 if(!retMapByDate.containsKey(oneData.getEntityId())){
                     List<OmsVirtualOrgMemberDept> elmList= new ArrayList<>();
                     elmList.add(oneData);
                     retMapByDate.put(oneData.getEntityId(),elmList);
                 }else{
                     retMapByDate.get(oneData.getEntityId()).add(oneData);
                 }
             }
         }
         //按内容id取最新一条
         List<OmsVirtualOrgMemberDept> retListData = new ArrayList<>();
         for(Map.Entry<String,List<OmsVirtualOrgMemberDept>> oneEntry : retMapByDate.entrySet()){
             retListData.add(oneEntry.getValue().get(0));
         }

         return retListData;
     } catch (Exception e) {
         e.printStackTrace();
         throw new BizException("-1",e,false);
     }

  }

    /**
   * 3-6-03查虚拟成员部门列表[2220]
   * gen by moon at 10/16/2022, 7:14:08 AM
   */
 @Trace(operationName = "3-6-03查虚拟成员部门列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  queryVirtualOrgMemberDeptList(QueryVirtualOrgMemberDeptListReq reqDto) {
     
        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByAsc("order_number");
queryWrapper.orderByDesc("operate_time");
            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }

    /**
   * 3-6-03批量查虚拟成员部门[2647]
   * gen by moon at 8/29/2022, 12:41:32 PM
   */
 @Trace(operationName = "3-6-03批量查虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
 @BanAuto
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  batchQueryVirtualOrgMemberDept(BatchQueryVirtualOrgMemberDeptReq reqDto) {
     try {
         QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
         if(reqDto.getVirtualOrgMemberDeptList()==null || reqDto.getVirtualOrgMemberDeptList().isEmpty()){
             return new ArrayList<>();
         }
         //将内容标识提取出来，要注意 这个地方的in 不是使用主键，要使用同名字段.
         List<String> ids = reqDto.getVirtualOrgMemberDeptList().stream().map(VirtualOrgMemberDeptDto::getEntityId).collect(Collectors.toList());
         queryWrapper.in("entity_id", ids);

         //正常构建查询条件
         Map<String, Object> fieldInfoMap = null;
         fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
         List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
         CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
         List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
         CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
         likeList.addAll(compareList);
         CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
//         queryWrapper.orderByDesc("order_number");
         queryWrapper.orderByDesc("operate_time");

         //执行查询
         List<OmsVirtualOrgMemberDept> retListDataTmp = super.list(queryWrapper);

         if(reqDto.getVirtualOrgMemberDeptList()!=null && reqDto.getVirtualOrgMemberDeptList().size()>0){
             if(reqDto.getVirtualOrgMemberDeptList().get(0).getEndTime()==null){
                 return retListDataTmp;
             }
         }

         //先构建索引
         Map<String,VirtualOrgMemberDeptDto> indexInfo = new HashMap<>();
         for(VirtualOrgMemberDeptDto oneMember : reqDto.getVirtualOrgMemberDeptList()){
             indexInfo.put(oneMember.getEntityId(),oneMember);
         }
         //按时间过滤
         Map<String,List<OmsVirtualOrgMemberDept>> retMapByDate = new HashMap<>();
         for(OmsVirtualOrgMemberDept oneData: retListDataTmp){
             VirtualOrgMemberDeptDto standData = indexInfo.get(oneData.getEntityId());
             //此处时间字段，一定是同名字段
             if(standData.getEndTime().compareTo(oneData.getStartTime())>=0 && standData.getEndTime().compareTo(oneData.getEndTime())<=0){
                 if(!retMapByDate.containsKey(oneData.getEntityId())){
                     List<OmsVirtualOrgMemberDept> elmList= new ArrayList<>();
                     elmList.add(oneData);
                     retMapByDate.put(oneData.getEntityId(),elmList);
                 }else{
                     retMapByDate.get(oneData.getEntityId()).add(oneData);
                 }
             }
         }
         //按内容id取最新一条
         List<OmsVirtualOrgMemberDept> retListData = new ArrayList<>();
         for(Map.Entry<String,List<OmsVirtualOrgMemberDept>> oneEntry : retMapByDate.entrySet()){
             retListData.add(oneEntry.getValue().get(0));
         }

         return retListData;
     } catch (Exception e) {
         e.printStackTrace();
         throw new BizException("-1",e,false);
     }

  }

    /**
   * 3-6-03批量删虚拟成员部门[2740]
   * gen by moon at 10/16/2022, 7:14:12 AM
   */
 @Trace(operationName = "3-6-03批量删虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchDeleteVirtualOrgMemberDept(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }
/**
   * 3-6-03删除虚拟成员部门[2616]
   * gen by moon at 10/16/2022, 7:14:11 AM
   */
 @Trace(operationName = "3-6-03删除虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deleteVirtualOrgMemberDept(String virtualOrgMemberDeptId ) {
     
      return super.removeById(virtualOrgMemberDeptId);
  }
/**
   * 3-6-03执行无约束查牵头部门[3307]
   * gen by moon at 3/30/2023, 12:39:01 PM
   */
 @Trace(operationName = "3-6-03执行无约束查牵头部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsVirtualOrgMemberDept  implementUnrestraintQueryLeadDept(ImplementUnrestraintQueryLeadDeptReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsVirtualOrgMemberDept> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsVirtualOrgMemberDept retData = retList.get(0);
                
                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 3-6-03批量改虚拟成员部门[3684]
   * gen by moon at 10/16/2022, 7:14:13 AM
   */
 @Trace(operationName = "3-6-03批量改虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchUpdateVirtualOrgMemberDept(List<OmsVirtualOrgMemberDept> omsVirtualOrgMemberDept) {
     
      if(omsVirtualOrgMemberDept==null || omsVirtualOrgMemberDept.size()==0){
        return false;
      }
        return super.saveOrUpdateBatch(omsVirtualOrgMemberDept);
      
  }
/**
   * 3-6-03构造虚拟成员部门验证数据[4249]
   * gen by moon at 10/16/2022, 7:14:15 AM
   */
 @Trace(operationName = "3-6-03构造虚拟成员部门验证数据")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  buildVirtualOrgMemDept(OmsVirtualOrgMemberDept omsVirtualOrgMemberDept) {
     omsVirtualOrgMemberDept.setVirtualOrgMemberDeptId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsVirtualOrgMemberDept.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsVirtualOrgMemberDept.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null &&  omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            omsVirtualOrgMemberDept.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsVirtualOrgMemberDept.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//ARCHIVE_CURRENT_INDUCTIONID
          }
omsVirtualOrgMemberDept.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsVirtualOrgMemberDept.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             omsVirtualOrgMemberDept.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsVirtualOrgMemberDept.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
omsVirtualOrgMemberDept.setIsValid("FALSE");
omsVirtualOrgMemberDept.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsVirtualOrgMemberDept.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsVirtualOrgMemberDept)){
        return omsVirtualOrgMemberDept.getVirtualOrgMemberDeptId();
     }else {
        return "-1";
     }
    
  }
/**
   * M3-6-03构造单条虚拟成员部门验证数据[4276]
   * gen by moon at 10/16/2022, 7:14:16 AM
   */
 @Trace(operationName = "M3-6-03构造单条虚拟成员部门验证数据")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  buildSingleVirtualOrgMemDept(OmsVirtualOrgMemberDept omsVirtualOrgMemberDept) {
     omsVirtualOrgMemberDept.setVirtualOrgMemberDeptId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsVirtualOrgMemberDept.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsVirtualOrgMemberDept.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null &&  omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            omsVirtualOrgMemberDept.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsVirtualOrgMemberDept.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//ARCHIVE_CURRENT_INDUCTIONID
          }
omsVirtualOrgMemberDept.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsVirtualOrgMemberDept.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             omsVirtualOrgMemberDept.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsVirtualOrgMemberDept.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
omsVirtualOrgMemberDept.setIsValid("FALSE");
omsVirtualOrgMemberDept.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsVirtualOrgMemberDept.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsVirtualOrgMemberDept)){
        return omsVirtualOrgMemberDept.getVirtualOrgMemberDeptId();
     }else {
        return "-1";
     }
    
  }
/**
   * M3-6-03一键删除单条虚拟成员部门验证数据[4421]
   * gen by moon at 10/16/2022, 7:14:17 AM
   */
 @Trace(operationName = "M3-6-03一键删除单条虚拟成员部门验证数据")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  autoDeleteSingleVirtualOrgMemDept(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }
/**
   * M3-6-03查询单条虚拟成员部门列表[4451]
   * gen by moon at 10/16/2022, 7:14:17 AM
   */
 @Trace(operationName = "M3-6-03查询单条虚拟成员部门列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  querySingleVirtualOrgMemDeptList(OmsVirtualOrgMemberDept omsVirtualOrgMemberDept) {
     
        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(omsVirtualOrgMemberDept);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * M3查询虚拟成员部门测试列表[5129]
   * gen by moon at 11/4/2022, 2:07:55 AM
   */
 @Trace(operationName = "M3查询虚拟成员部门测试列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  queryVirtualOrgMemDeptTestDataList(QueryVirtualOrgMemDeptTestDataListReq reqDto) {

        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-3-06批量查询虚拟成员部门列表By部门Ids[5726]
   * gen by moon at 1/18/2023, 2:03:55 AM
   */
 @Trace(operationName = "3-3-06批量查询虚拟成员部门列表By部门Ids")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  batchQueryVirtualOrgMemberDeptListByIds(BatchQueryVirtualOrgMemberDeptListByIdsReq reqDto) {

        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getVirtualOrgMemberDeptList()==null || reqDto.getVirtualOrgMemberDeptList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("dept_id", reqDto.getVirtualOrgMemberDeptList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByAsc("order_number");
queryWrapper.orderByDesc("operate_time");
            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * M3-06-03查询单条虚拟成员部门详情测试[6132]
   * gen by moon at 3/30/2023, 12:39:02 PM
   */
 @Trace(operationName = "M3-06-03查询单条虚拟成员部门详情测试")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsVirtualOrgMemberDept  querySingleVirtualOrgMemDeptDetail(QuerySingleVirtualOrgMemDeptDetailReq reqDto) {

        try {

            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsVirtualOrgMemberDept> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsVirtualOrgMemberDept retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 3-6-03批量查询虚拟成员部门By内容ID[7124]
   * gen by moon at 6/3/2023, 8:22:34 PM
   */
 @Trace(operationName = "3-6-03批量查询虚拟成员部门By内容ID")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  batchQueryVirtualOrgMemberDeptByContId(BatchQueryVirtualOrgMemberDeptByContIdReq reqDto) {

        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            if(reqDto.getVirtualOrgMemberDeptList()==null || reqDto.getVirtualOrgMemberDeptList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("entity_id", reqDto.getVirtualOrgMemberDeptList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-6-03新增工作任务虚拟成员部门[8055]
   * gen by moon at 12/2/2023, 4:29:00 PM
   */
 @Trace(operationName = "3-6-03新增工作任务虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addWorkTaskVirtualOrgMemberDept(OmsVirtualOrgMemberDept omsVirtualOrgMemberDept) {
     omsVirtualOrgMemberDept.setVirtualOrgMemberDeptId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsVirtualOrgMemberDept.setIsArchive("FALSE");
omsVirtualOrgMemberDept.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsVirtualOrgMemberDept.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null &&  omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            omsVirtualOrgMemberDept.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
omsVirtualOrgMemberDept.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsVirtualOrgMemberDept.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(omsVirtualOrgMemberDept!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle()!=null && omsVirtualOrgMemberDept.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             omsVirtualOrgMemberDept.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
omsVirtualOrgMemberDept.setIsValid("FALSE");
omsVirtualOrgMemberDept.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsVirtualOrgMemberDept.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsVirtualOrgMemberDept)){
        return omsVirtualOrgMemberDept.getVirtualOrgMemberDeptId();
     }else {
        return "-1";
     }

  }
/**
   * 3-6-03修改虚拟成员部门[8092]
   * gen by moon at 12/6/2023, 6:16:43 AM
   */
 @Trace(operationName = "3-6-03修改虚拟成员部门")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateVirtualOrgMemberDept(OmsVirtualOrgMemberDept omsVirtualOrgMemberDept) {
     omsVirtualOrgMemberDept.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsVirtualOrgMemberDept.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        return super.updateById(omsVirtualOrgMemberDept);
  }
/**
   * 3-6-03查询目标内容部门小圈子详情[9248]
   * gen by moon at 4/4/2024, 10:02:38 AM
   */
 @Trace(operationName = "3-6-03查询目标内容部门小圈子详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsVirtualOrgMemberDept  queryTargetContDeptSmallCircleDetail(QueryTargetContDeptSmallCircleDetailReq reqDto) {

        try {

            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsVirtualOrgMemberDept> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsVirtualOrgMemberDept retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 3-6-03查询目标内容部门小圈子列表[9347]
   * gen by moon at 4/7/2024, 8:48:53 AM
   */
 @Trace(operationName = "3-6-03查询目标内容部门小圈子列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsVirtualOrgMemberDept>  queryTargetContDeptSmallCircleList(QueryTargetContDeptSmallCircleListReq reqDto) {

        try {
            QueryWrapper<OmsVirtualOrgMemberDept> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsVirtualOrgMemberDept.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsVirtualOrgMemberDept.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsVirtualOrgMemberDept>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
}
